<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class CategoryRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * validation rules for user
     *
     * @return array
     */
    public function rules()
    {
        $id = $this->route('category');
        if($this->isMethod('post')){
            return [
                'name' => 'required|unique:categories',
            ];
        }else{
            return [
                'name' => 'required|unique:categories,name,'.$id,
            ];
        }
    }

    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => _("请输入分类名称"),
            'name.unique'  => _("分类名称已存在"),
        ];
    }
}
